<?php

namespace App\Listeners;

use App\Events\ResourceRequested;
use App\RequestLog;
use Illuminate\Support\Facades\Log;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class ResourceRequestedListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle(ResourceRequested $event)
    {
        Log::channel('requests')->info('Request from ' . $event->ip . ' to repository ' . $event->repository->name . ' for ' . $event->path);
        $log = new RequestLog();
        $log->repository_id = $event->repository->id;
        $log->path = $event->path;
        $log->ip = $event->ip;
        $log->save();
    }
}
